home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / util / shell / axuucp_0_1.lha / axsh / rexx / ax-uucico.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1995-03-22  |  3.9 KB  |  146 lines

  1. /****** axuucp/ax-uucico *****************************************************
  2. *
  3. *   NAME
  4. *    ax-uucico - UUCP file transfer daemon for local feeds
  5. *
  6. *   SYNOPSIS
  7. *    rx ax-uucico.rexx [feed]
  8. *
  9. *   DESCRIPTION
  10. *    ax-uucico is similar to uucico but does only perform a media-based
  11. *    filecopy instead of a data transfer via modem.
  12. *
  13. *    ax-uucico takes one single argument: the system name.  ax-uucico
  14. *    changes into the spool directory for this system and processes
  15. *    all files matching the pattern "C.system#?" with system truncated
  16. *    to the first 7 chars.  The files are copied according to the
  17. *    specifications in the control files; only send requests (S) are
  18. *    processed, that means receive requests submitted with the uucp
  19. *    command won't work, they are silently ignored and the command
  20. *    file gets deleted without further notice.
  21. *
  22. *   AUTHOR
  23. *    Tobias Ferber <tf@ganymed.hall.sub.org>
  24. *
  25. ******************************************************************************
  26. *
  27. */
  28.  
  29. feed = left(arg(1),min(length(arg(1)),7))
  30.  
  31. if words(feed) < 1 then do
  32.   say 'usage: ax-uucico [feed]'
  33.   exit 10
  34.   end
  35.  
  36. spooldir = strfmt(axconfig("axuucp.spooldir"),"%u",feed)
  37.  
  38. if ~exists(spooldir) then do
  39.   say 'ax-uucico: No such spool directory "'spooldir'"'
  40.   exit 10
  41.   end
  42.  
  43. tempfile = "T:ax-uucico." || pragma('Id')
  44. pat      = "C." || feed || "?" || "????"
  45.  
  46. /**/
  47.  
  48. address command 'List FILES DIR "'spooldir'" PAT "'pat'" LFORMAT "%p%n" > "'tempfile'"'
  49. call open('fp',tempfile)
  50. do until eof('fp')
  51.   fname=readln('fp')
  52.   if words(fname) > 0 then do
  53.     call uucico(fname)
  54.     address command 'Delete QUIET "'fname'"'
  55.     end
  56.   end
  57.  
  58. call close('fp')
  59. if exists(tempfile) then address command 'Delete QUIET "'tempfile'"'
  60. exit
  61.  
  62. /**/
  63.  
  64. uucico: procedure expose spooldir
  65.   parse arg cfile
  66.   if open('cf',cfile) then do
  67.     do until eof('cf')
  68.       str = readln('cf')
  69.       if (words(str) > 0) & (left(str,1) ~= '#') then do
  70.         parse var str cmd ' ' src ' ' dst ' ' .
  71.         select
  72.           when cmd='S' then do
  73.             if exists(spooldir || src) then do
  74.                address command 'Copy QUIET FROM "'spooldir || src'" TO "'spooldir || dst'"'
  75.                address command 'Delete QUIET "'spooldir || src'"'
  76.                end
  77.             else say 'ax-uucico: could not send "'src'" (File not found)'
  78.             end
  79.           otherwise say 'ax-uucico: ignoring "'str'"'
  80.           end
  81.         end
  82.       end
  83.     call close('cf')
  84.     end
  85.   else say 'ax-uucico: could not read "'cfile'"'
  86.   return
  87.  
  88. /*@<axconfig><strfmt>*/
  89.  
  90. /* get an AXsh configuration value */
  91.  
  92. axconfig: procedure
  93.   tempfile = "T:axconfig." || pragma('Id')
  94.   rc_index  = "AXsh:rexx/rc.index"
  95.   var_val=""; var_file=""; var_defval="";
  96.  
  97.   parse upper arg var_name
  98.   if left(var_name,1) ~= '%' then var_name = '%'var_name
  99.   if right(var_name,1) ~= ':' then var_name = var_name':'
  100.  
  101.   if open('idx',rc_index,'Read') then do
  102.     do until (eof('idx') | (var_file~=''))
  103.       str= translate(readln('idx'),' ',d2c(9))
  104.       if words(str) > 0 then do
  105.         parse var str vname ' ' fname '"' defval '"'
  106.         if upper(vname) = var_name then do
  107.           var_file= strip(fname,'B',' 'd2c(9))
  108.           var_defval= defval
  109.           end
  110.         end
  111.       end
  112.     call close('idx')
  113.     end
  114.   else say 'Could not read "'rc_index'"'
  115.  
  116.   if words(var_file) > 0 then do
  117.     if open('rc',var_file,'Read') then do
  118.       do until (eof('rc') | (var_val~=''))
  119.         str= translate(readln('rc'),' ',d2c(9))
  120.         if upper(word(str,1)) = var_name then var_val = strip(readln('rc'),'B',' 'd2c(9))
  121.         end
  122.       call close('rc')
  123.       end
  124.     else say 'Could not examine "'var_file'" for' var_name
  125.     end
  126.   else do
  127.     if words(var_defval) > 0 then var_val= var_defval
  128.     else say 'No such config variable:' var_name
  129.     end
  130.  
  131.   return var_val
  132.  
  133.  
  134. /* substitute all occurences of 'fmt' in 'str' by 'val' */
  135.  
  136. strfmt: procedure
  137.   parse arg str,fmt,val
  138.   p= pos(fmt,str)
  139.   do while p>0
  140.     str= left(str,p-1) || val || substr(str,p+length(fmt))
  141.     p= pos(fmt,str)
  142.     end
  143.   return str
  144.  
  145.  
  146.